<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN\" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="arq" uri="/tld/arquitectura.tld" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="display" uri="http://displaytag.sf.net/el" %>
<%@ taglib prefix="dynamic" uri="/tld/dynamic.tld" %>

<html>
<head>
<jsp:include page="Head.jsp"/>

<!--Round the menu tabs-->
<script type="text/javascript">
    window.onload = function()
    {
        Nifty("ul#nav a", "small transparent top");
    }



    //Add this video to the favourite list of the user.
    //Function that execute a JSON call to the server to add this YouTube video to the personal list of the user.
    function addToMyList()
       {
       if( confirm('Add this video to your favourites?') )
       {
           var args = new Array();
           var userLogin = '<dynamic:user />';
           var youTubeId = '<c:out value="${command.videoProcess.youTubeId}"/>';
           args[0] = "'" + youTubeId + "'";
           args[1] = "'" + userLogin + "'";
           jsonEntityArrayCall( "videoFacade", "addVideo", args, cb_addToFavourites  );
       }
    }

    //Call back to the JSON call to add the video to the user favourites.
    function cb_addToFavourites( result, exception )
    {
       if( exception )
       {
           alert( exception );
       }
       else
       {
           if( result == 0 ) //OK
           {
               alert('OK!');
           }
           else if( result == 1 ) //No user
           {
               alert('Ooops! We don not know who are you. Are you logged in?');
           }
           else if( result == 2 ) //Video already added.
           {
               alert('This video was already added to your favourites!');
           }
       }
    }

</script>



</head>
<body>
<c:set var="currentPage" value="" scope="request" />
<jsp:include page="Menu.jsp"/>

<br><br><br><br><br><br>
<table align="center" width="50%">
    <tr align="center">
        <td>
            <h2>State of video <i><b style="color:#666;"><c:out value="${command.videoProcess.title}"/></b></i></h2>
        </td>
    </tr>
</table>

<form:form action="checkVideoState.htm" method="post">
    <form:hidden path="videoProcess.id" />

    <table align="center" width="50%">
        <tr align="center">
            <td class="textLogin">
                <c:choose>
                    <c:when test="${command.stateCode == -1}"> <!-- USER NOT OWN THE VIDEO -->
                        <h2>Sorry, you entered a user that do not upload this video</h2>
                    </c:when>
                    <c:when test="${command.stateCode == 0}"> <!-- PROCESSING -->
                        <h2>The video is still being processing</h2>
                    </c:when>
                    <c:when test="${command.stateCode == 1}"> <!-- REJECTED -->
                        <h2>Your video has been Rejected</h2>
                    </c:when>
                    <c:when test="${command.stateCode == 2}"> <!-- FAILED -->
                        <h2>The upload of your video has failed</h2>
                    </c:when>
                    <c:when test="${command.stateCode == 3}"> <!-- INCOMPLETE -->
                        <h2>The upload of the video is incomplete</h2>
                    </c:when>
                    <c:when test="${command.stateCode == 4}"> <!-- UPLOAD COMPLETE -->
                        <h2 style="color:green;">The upload of the video is COMPLETE</h2><br>
                        <dynamic:flashButton text="Add to my favourites" link="addToMyList()" />
                    </c:when>
                    <c:otherwise>
                        <h2 style="color:red;">STATE NOT SUPPORTED. Contact the administrator</h2>
                    </c:otherwise>
                </c:choose>
            </td>
        </tr>
    </table>


</form:form>


</body>
</html>